import os
import platform
import sys
import re #Regular Expressions
from PyQt4.QtGui import *
from PyQt4.QtCore import *
#import qrc_resources
import main as ui_trail

__version__ = "1.0.0"

class MainWindow(QMainWindow, ui_trail.Ui_MainWindow):
    """ """
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.filename = None
        self.setupUi(self)
        QObject.connect(self.pushButton_Start, SIGNAL("clicked()"), self.takeInput)
        QObject.connect(self.textbox_variables, SIGNAL("returnPressed()"), self.takeInput)

    def takeInput(self):
        variables = str(self.textbox_variables.text())
        objectiveFunctions = str(self.textbox_objectiveFunctions.text())
        constraintFunctions = str(self.textbox_constraintFunctions.text())

        ga.searchSpace = str(self.textbox_searchSpace.text())
        ga.algorithmSettings['populationSize'] = int(self.textbox_populationSize.text())
        ga.algorithmSettings['iterations'] = int(self.textbox_iterationCount.text())
        ga.algorithmSettings['crossoverRate'] = float(self.textbox_crossoverRate.text())
        ga.algorithmSettings['mutationRate'] = float(self.textbox_muatationRate.text())
        

        if self.radioButton_GA.isChecked():
            ga.algorithmSettings['populationSize'] = int(self.textbox_populationSize.text())
            self.textBrowser_output.append("Implementing Genetic Algorithm \n")
            #self.textBrowser_output.append("Cross over Rate is 0.08 \n")
            #self.textBrowser_output.append("Mutation Rate is 0.01 \n")

        if self.checkBox_IVP.isChecked():
            self.textBrowser_output.append("Integer Value problem selected")

        for i in range(1001):
            self.progressBar.setValue(i/10)
        RESULT = ga.optimize(variables,  objectiveFunctions, constraintFunctions)
        self.textBrowser_output.append('                                         ')
        self.textBrowser_output.append("   ")
        self.textBrowser_output.append('Result:')
        self.textBrowser_output.append(str(RESULT))
        
        

if __name__ == "__main__":
    import ga
    app = QApplication(sys.argv)
    application = MainWindow()
    application.show()
    app.exec_()
